package com.woniuxy.store.core.service.impl;

import com.woniuxy.store.core.exception.LoginException;
import com.woniuxy.store.core.model.MdStoreUser;
import com.woniuxy.store.core.mapper.MdStoreUserMapper;
import com.woniuxy.store.core.service.MdStoreUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author gmx
 * @since 2021-07-06
 */
@Service
public class MdStoreUserServiceImpl extends ServiceImpl<MdStoreUserMapper, MdStoreUser> implements MdStoreUserService {

    @Resource
    private MdStoreUserMapper mdStoreUserMapper;

    @Override
    public MdStoreUser subLogin(MdStoreUser mdStoreUser) {
        MdStoreUser user = this.mdStoreUserMapper.selectByUsername(mdStoreUser.getUsername());
        if (user == null){
            throw new LoginException(500,"账户不存在");
        }
        if (!mdStoreUser.getPassword().equals(user.getPassword())){
            throw new LoginException(500,"密码错误");
        }
        return user;
    }
}
